<script setup lang="ts">
import { reqHospitalLevelAndRegion } from '@/apis/home';
import { ref, onMounted } from 'vue';
import { HospitalLevelAndRegionArr, HospitalLevelAndRegionResponseData } from '@/apis/home/type';

const levelArr = ref<HospitalLevelAndRegionArr>([])
const activeFlag = ref<string>('')
const $emit = defineEmits(['getLevel'])

onMounted(() => {
  getLevel()
})

const getLevel = async () => {
  const res: HospitalLevelAndRegionResponseData = await reqHospitalLevelAndRegion("HosType")
  // console.log(res)
  if(res.code = 200){
    levelArr.value = res.data
  }
}

const changeLevel = (level: string) => {
  activeFlag.value = level
  // 触发自定义事件
  $emit('getLevel', level)
}
</script>

<script lang="ts">
export default {
  name: 'Level'
}
</script>


<template>
  <div class="level">
    <h2>医院</h2>
    <div class="content">
      <div class="left">等级:</div>
      <ul class="hospital">
        <li :class="{active: activeFlag==''}" @click="changeLevel('')">全部</li>
        <li :class="{active: activeFlag==level.value}" v-for="(level) in levelArr" :key="level.value" @click="changeLevel(level.value)">{{ level.name }}</li>
      </ul>
    </div>
  </div>
</template>



<style scoped lang="scss">
.level{
  color: #7f7f7f;
  h2{
    font-weight:700;
    margin: 10px  0px;
  }
  .content{
    display: flex;
  }
  .left{
    margin-top: 15px;
    margin-right: 10px;
  }
  .hospital{
    display: flex;
    li{
      margin: 15px 0 0 10px;
      &.active{
        color: #55a6fe;
      }
    }
    li:hover{
        color: #55a6fe;
        cursor: pointer;
      }
  }
}
</style>